// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	/*------ 公共接口 ------*/
	// 获取支付方式
	let getPayType = (params = '') => vm.$u.get('/System/ApiSystem/getPayType', params);
	// 获取配送方式
	let getDelivery = (params = '') => vm.$u.post('/System/ApiSystem/getDelivery', params);
	// 获取设置项
	let getBasicField = (params = '') => vm.$u.post('/System/ApiSystem/getBasicField', params);
	// 获取订阅消息模板id
	let getTemplateMessageId = (params = '') => vm.$u.post('/System/ApiSystem/getTemplateMessageId', params);

	/*------ 登录 ------*/
	let login = (params = '') => vm.$u.post('/User/ApiUser/login', params);
	// 获取openID
	let getOpenId = (params = '') => vm.$u.post('/Common/Login/login', params);
	// 解析微信手机号
	let decryptData = (params = '') => vm.$u.post('/Common/Login/decryptData', params);
	// 发送短信验证码
	let sendMobileCode = (params = '') => vm.$u.post('/Common/SmsCode/sendMobileCode', params);

	// 首页
	let getHome = (params = '') => vm.$u.get('/System/ApiPage/home', params);
	/*------ 购物车 ------*/
	// 清空购物车
	let clearCart = (params = '') => vm.$u.delete('/Cart/ApiCart/clear', params);
	// 批量删除商品
	let delCart = (params = '') => vm.$u.put('/Cart/ApiCart/del', params);
	// 选中/取消商品
	let selectionCart = (params = '') => vm.$u.post('/Cart/ApiCart/selection', params);
	// 修改购买数量
	let numCart = (params = '') => vm.$u.put(`/Cart/ApiCart/num`, params);
	// 加入购物车
	let addCart = (params = '') => vm.$u.put(`/Cart/ApiCart/add`, params);
	// 购物车
	let getCart = (params = '') => vm.$u.get(`/Cart/ApiCart/get`, params);
	// 确认订单
	let confirmCart = (params) => vm.$u.post(`/Cart/ApiCart/confirm`, params);
	// 立即购买
	let buyNow = (params) => vm.$u.post(`/Cart/ApiCart/buyNow`, params);

	/*------ 商品 ------*/
	// 商品详情
	let getGoodsDetail = (id, params = '') => vm.$u.get(`/Goods/ApiGoods/get/${id}`, params);
	// 商品列表
	let searchGoods = (params = '') => vm.$u.post(`/Goods/ApiGoods/search`, params);
	// 分类列表
	let getAllCate = (params = '') => vm.$u.get(`/Goods/ApiGoods/getAll`, params);
	// 收藏/取消
	let collectGoods = (id, params = '') => vm.$u.get(`/Goods/ApiCollect/collect/${id}`, params);
	// 我的收藏
	let collectList = (params = '') => vm.$u.get(`/Goods/ApiCollect/getAll`, params);
	/*------ 收货地址 ------*/
	// 删除
	let delAddress = (id, params = '') => vm.$u.delete(`/User/ApiAddress/del/${id}`, params);
	// 编辑
	let editAddress = (id, params = '') => vm.$u.put(`/User/ApiAddress/edit/${id}`, params);
	// 获取地址详情
	let detailAddress = (id, params = '') => vm.$u.get(`/User/ApiAddress/get/${id}`, params);
	// 获取地址列表
	let addressList = (params = '') => vm.$u.post(`/User/ApiAddress/getAll`, params);
	// 添加地址
	let addAddress = (params = '') => vm.$u.post(`/User/ApiAddress/add`, params);
	/*------ 订单 ------*/
	// 确认收货
	let finishOrder = (id, params = '') => vm.$u.put(`/Order/ApiOrder/finish/${id}`, params);
	// 取消订单
	let cancelOrder = (id, params = '') => vm.$u.put(`/Order/ApiOrder/cancel/${id}`, params);
	// 订单详情
	let getOrderDetail = (id, params = '') => vm.$u.get(`/Order/ApiOrder/get/${id}`, params);
	// 订单列表
	let orderList = (params) => vm.$u.post(`/Order/ApiOrder/search`, params);
	// 创建订单
	let createOrder = (params) => vm.$u.post(`/Order/ApiOrder/create`, params);
	// 立即支付
	let rePay = (params) => vm.$u.post(`/Order/ApiOrder/rePay`, params);
	/*------ 优惠券 ------*/
	// 待领取列表
	let couponList = (params) => vm.$u.post(`/Market/ApiCoupon/list`, params);
	// 领取
	let receiveCoupon = (id, params = '') => vm.$u.get(`/Market/ApiCoupon/receive/${id}`, params);
	// 我的优惠券
	let couponSearch = (params) => vm.$u.post(`/Market/ApiCoupon/search`, params);
	/*------ 客户 ------*/
	// 用户详情
	let getCustomerInfo = (params) => vm.$u.get(`/Customer/ApiCustomer/getCustomerInfo`, params);
	// 修改用户信息
	let editCustomerInfo = (params) => vm.$u.post(`/Customer/ApiCustomer/editCustomerInfo`, params);


	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		/*------ 公共接口 ------*/
		getPayType,
		getDelivery,
		getBasicField,
		getTemplateMessageId,
		/*------ 登录 ------*/
		login,
		getOpenId,
		decryptData,
		sendMobileCode,
		/*------ 首页 ------*/
		getHome,
		/*------ 购物车 ------*/
		clearCart,
		delCart,
		selectionCart,
		numCart,
		addCart,
		getCart,
		confirmCart,
		buyNow,
		/*------ 商品 ------*/
		getGoodsDetail,
		searchGoods,
		getAllCate,
		collectGoods,
		collectList,
		/*------ 收货地址 ------*/
		delAddress,
		editAddress,
		detailAddress,
		addressList,
		addAddress,
		/*------ 订单 ------*/
		finishOrder,
		cancelOrder,
		getOrderDetail,
		orderList,
		createOrder,
		rePay,
		/*------ 优惠券 ------*/
		couponList,
		receiveCoupon,
		couponSearch,
		/*------ 客户 ------*/
		getCustomerInfo
	};
}

export default {
	install
}
